#!/bin/bash

# exit on error
set -e

VERSION='bf4a4c8ae9eab0801a32316a40ef63b8a2247ae3'
BASEDIR="$PWD"
SRCDIR="$BASEDIR/osv-utils-xlab"

# enable parallel build
export MAKEFLAGS="-j `nproc`"

if [ ! -d osv-utils-xlab ]; then
    # Checkout code
    git clone https://github.com/mikelangelo-project/osv-utils-xlab
    (cd osv-utils-xlab && git checkout $VERSION)
fi

# compile
(cd osv-utils-xlab && make -j $MAKEFLAGS)

# Generate usr.manifest
cat <<EOF >"$BASEDIR/usr.manifest"
/usr/bin/cd.so:       ${SRCDIR}/cd.so
/usr/bin/sleep.so:    ${SRCDIR}/sleep.so
/usr/bin/cat.so:      ${SRCDIR}/cat.so
/usr/bin/echo.so:     ${SRCDIR}/echo.so
EOF

